package io.kblog.service;

import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class WxMaServiceImpl extends BaseWxMaServiceImpl {
    @NotNull
    @Contract("_,_ -> new")
    public static BaseWxMaService getInstance(@NotNull String appId, @NotNull String secret) throws WxErrorException {
        return new WxMaServiceImpl(appId, secret);
    }
    public WxMaServiceImpl(@NotNull String appId, @NotNull String secret) {
        setWxMaConfig(appId, secret);
    }

    void setWxMaConfig(@NotNull String appId, @NotNull String secret) {
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
        wxMaConfig.setAppid(StringUtils.trimToNull(appId));
        wxMaConfig.setSecret(StringUtils.trimToNull(secret));
        setWxMaConfig(wxMaConfig);
    }
}
